<?php


namespace app\admin\model\base;


use app\BaseModel;

class StudentPaper extends BaseModel
{
    /**
     * 获取列表
     * @param array $where
     * @param int $page
     * @param int $limit
     * @param string $orderby
     * @param string $field
     * @return array
     */
    public static function getList(array $where, int $page, int $limit, string $orderby = '', string $field = '*'): array
    {
        //查询
        $data = self::field($field)
            ->with(['student','paper','admin'])
            ->where($where)
            ->order($orderby)
            ->paginate(['list_rows' => $limit, 'page' => $page], false)
            ->toArray();
        return $data;
    }

    /**
     * 管理考试答题
     */
    public function studentPaperSubject(){
        return $this->hasMany(StudentPaperSubject::class,'student_paper_id','id');
    }

    /**
     * 管理考试题目
     */
    public function paperSubject(){
        return $this->hasMany(PaperSubject::class,'paper_id','id');
    }

    /**
     * 管理考试题目
     */
    public function student(){
        return $this->hasOne(Student::class,'id','student_id')->field('username,realname,id,special_id,grades_id,classes_id')->with(['special']);
    }

    /**
     * 管理考试题目
     */
    public function paper(){
        return $this->hasOne(Paper::class,'id','paper_id')->field('name,id,special_id,start_time,end_time,time')->with(['special']);
    }

    /**
     * 关联老师
     */
    public function admin(){
        return $this->hasOne(Admin::class,'id','create_user')->field('name,id,phone,mobile,duties_id')->with(['duties']);
    }

}